<?php

error_reporting(E_ALL);

/**
 * ECommerce - class.ControladorVenta.php
 *
 * $Id$
 *
 * This file is part of ECommerce.
 *
 * Automatically generated on 28.11.2011, 11:38:30 with ArgoUML PHP module 
 * (last revised $Date: 2010-01-12 20:14:42 +0100 (Tue, 12 Jan 2010) $)
 *
 * @author firstname and lastname of author, <author@example.org>
 */

if (0 > version_compare(PHP_VERSION, '5')) {
    die('This file was generated for PHP 5');
}

/* user defined includes */
// section -84-27-7--73-773350a1:133d67ac203:-8000:0000000000001493-includes begin
//clases que vamos a utilizar en el controlador de la venta
require_once('class.VistaVenta.php');
require_once('class.ModeloVenta.php');
// section -84-27-7--73-773350a1:133d67ac203:-8000:0000000000001493-includes end

/* user defined constants */
// section -84-27-7--73-773350a1:133d67ac203:-8000:0000000000001493-constants begin
// section -84-27-7--73-773350a1:133d67ac203:-8000:0000000000001493-constants end

/**
 * Short description of class ControladorVenta
 *
 * @access public
 * @author firstname and lastname of author, <author@example.org>
 */
class ControladorVenta
{
    // --- ASSOCIATIONS ---


    // --- ATTRIBUTES ---

    /**
     * Short description of attribute miVistaVenta
     *
     * @access public
     * @var VistaVenta
     */
    public $miVistaVenta = null;

    /**
     * Short description of attribute miModeloVenta
     *
     * @access public
     * @var ModeloVenta
     */
    public $miModeloVenta = null;

    // --- OPERATIONS ---

    /**
     * Short description of method ListaVenta
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return void
     */
    public function ListaVenta()
    {
        // section -84-27-7--73-773350a1:133d67ac203:-8000:000000000000149C begin
      //si la variable de sesion venta tiene un valor, entonces se manda llamar los articulos que ha agregado al carrito de compras
      //los articulos estan unicamente en la sesion
       if(@$_SESSION["venta"])   
       {   
       $datos=$this->miModeloVenta->getRowsByUser($_SESSION["venta"]);		
	   $this->miVistaVenta->ListaUser($datos);
       }
       else
       {
       	echo "<br><br>";
       	echo"Aun no estas registrado o no has seleccionado ningun articulo.";
       }
        // section -84-27-7--73-773350a1:133d67ac203:-8000:000000000000149C end
    }

    /**
     * Short description of method Alta
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return void
     */
    public function Alta()
    {
        // section -84-27-7--73-773350a1:133d67ac203:-8000:000000000000149E begin
        if(!@$_SESSION["venta"])
        {
        	$_SESSION["venta"]=array();
        }
        //se agrega el articulo al array de la sesion
        array_push($_SESSION["venta"],@$_REQUEST[id]);
        echo "<br><br>";
        echo "Haz agregado ";
        echo count($_SESSION["venta"]);
        echo " articulos en tu carrito de compras.<br>";
        echo "<a href='index.php?controlador=tienda'> Sigue añadiendo!</a> o ";
        echo "<a href='index.php?controlador=comprar'>finaliza tu compra!</a>";
        // section -84-27-7--73-773350a1:133d67ac203:-8000:000000000000149E end
    }

    /**
     * Short description of method Borrar
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return void
     */
    public function Borrar()
    {
        // section -84-27-7--73-773350a1:133d67ac203:-8000:00000000000014A0 begin
      //borra un articulo del array de la sesion
        $key=array_search($_REQUEST["id"],$_SESSION['venta']);
        unset($_SESSION["venta"][$key]);
        echo "<br><br>";
        echo " Haz eliminado un articulo de tu carrito de compras.<br>";
        echo "<a href='index.php?controlador=tienda'> Sigue añadiendo!</a> o ";
        echo "<a href='index.php?controlador=comprar'>finaliza tu compra!</a>";
        // section -84-27-7--73-773350a1:133d67ac203:-8000:00000000000014A0 end
    }

    /**
     * Short description of method Controlador
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return void
     */
    public function ControladorVenta()
    {
        // section -84-27-7--73-773350a1:133d67ac203:-8000:00000000000014A2 begin
        $this->miModeloVenta = new ModeloVenta();		
		$this->miVistaVenta = new VistaVenta();		
		//var_dump($_REQUEST);
		// VISTA 
		if(@$_REQUEST["controlador"]=="tienda" || @$_REQUEST[Cancelar])
		{
			$this->ListaProds();
		}
		else 
		{
			if(@$_REQUEST["controlador"]=="eliminarArticulo") 	
				$this->Borrar();
			if(@$_REQUEST["controlador"]=="agregarArticulo")
				$this->Alta();			
			if(@$_REQUEST["controlador"]=="comprar") 
				$this->ListaVenta();
			if(@$_REQUEST["controlador"]=="pagar") 
				$this->procesar();
			if(@$_REQUEST["controlador"]=="reporteVendidos") 
				$this->reporteVendidos();
			if(@$_REQUEST["controlador"]=="reporteDetallado") 
				$this->reporteDetallado();
		}
        // section -84-27-7--73-773350a1:133d67ac203:-8000:00000000000014A2 end
    }

    /**
     * Short description of method ListaProds
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return void
     */
    public function ListaProds()
    {
        // section -84-27-7--73-773350a1:133d67ac203:-8000:00000000000014AD begin
      //se carga el catalogo de productos
       $datos=$this->miModeloVenta->getAllProds();		
	   $this->miVistaVenta->Lista($datos);	
        // section -84-27-7--73-773350a1:133d67ac203:-8000:00000000000014AD end
    }

    /**
     * Short description of method procesar
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return void
     */
    public function procesar()
    {
        // section -84-27-7--73-773350a1:133d67ac203:-8000:00000000000014AF begin
       if(@$_SESSION["venta"])   
       {   
       $datos=$this->miModeloVenta->insertRow($_SESSION["venta"]);
       echo "<br><br>";
       echo "Transaccion realizada con exito!";		
       unset($_SESSION["venta"]);
	  // $this->miVistaVenta->ListaUser($datos);
       }
       else
       {
       	echo "<br><br>";
       	echo"Aun no estas registrado o no has seleccionado ningun articulo.";
       }
        // section -84-27-7--73-773350a1:133d67ac203:-8000:00000000000014AF end
    }

    /**
     * Short description of method reporteVendidos
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return void
     */
    public function reporteVendidos()
    {
        // section -64--88-1--71-4dd119c:133dc13dce6:-8000:0000000000000DC0 begin
       $datos=$this->miModeloVenta->getReporte();		
	   $this->miVistaVenta->ListaReporte($datos);
        // section -64--88-1--71-4dd119c:133dc13dce6:-8000:0000000000000DC0 end
    }

    /**
     * Short description of method reporteDetallado
     *
     * @access public
     * @author firstname and lastname of author, <author@example.org>
     * @return void
     */
    public function reporteDetallado()
    {
        // section -84-27-7--75-6e35e6be:133eb7391de:-8000:0000000000000DCA begin
       $datos=$this->miModeloVenta->getReporte();		
	   $this->miVistaVenta->ListaReporteDetallado($datos);
        // section -84-27-7--75-6e35e6be:133eb7391de:-8000:0000000000000DCA end
    }

} /* end of class ControladorVenta */

?>